#include<stdio.h>
#include<at89c51ed2.h>
#include<mcs51reg.h>
#include<malloc.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include "lcd.h"
#include "io.h"
	
	
#define HEAP_SIZE 200	/*heap size of 1600*/
unsigned char xdata heap[HEAP_SIZE];

void lcdTest()
{	

int breaker;
char *  value;
char *  value1;
//int x;
//int y;
int i;
//int num;
//char tmp;
char choice2;
int initial;
xdata char * str;
char row;
char column;
//int test;



/*initialisation functions*/
init_dynamic_memory((MEMHEADER xdata *)heap, HEAP_SIZE); 


value=(xdata char *)malloc(10);






/*LCD Function test Program */

value1=(char *)malloc(50);
/*initialisation functions*/



breaker=0;
initial=0;
while(1){
	 if(breaker==1){
	break;
	}
printf_tiny("  Welcome to              LCD Test Program\n\r");
newLine();
printf_tiny("Enter which function you wish to test\n\r");
newLine();
printf_tiny("1 : lcdgotoaddr()	2 : lcdgotoxy()\n\r");
printf_tiny("3 : lcdputch()		4 : lcdputstr()\n\r");
printf_tiny("5: Clear LCD Display\n\r\t\t\t");
printf_tiny("Press R to return to Main Menu\n\r");

if(initial==0){
lcdgotoxy('1','1');
lcdputstr("Welcome to LCD      Test");
}

choice2=toupper(getchar());

if(initial==0){
	lcdData(0x01,0);
	lcddelay(500);
}
initial++;



switch (choice2)
{

case '1': printf("Testing lcdgotoaddr\n\r ");
/*****************************************************************/
			/*lcd go to address test*/
printf("Enter the Address you want to seek to, control will print a X at that location\t ");
i=0;
gets(value);

lcdgotoaddr(lcd_asciiInput(value));
lcdputch('X');
free(value);
break;

/*******************************************************************/
   case '2' : printf("Testing lcdgotoxy\n\r"); /*lcdgotoxy   */
   
   
	printf("\n\rEnter Row:\t");
	row=getchar();
	putchar(row);
    printf("\n\rEnter Column:\t");
	column=getchar();
	putchar(column);
   	lcdgotoxy(row,column);
   	lcdputch('X');
   	
  	 break;
   
case '3': printf("Testing putch\n\r");
   		  newLine();
   		  printf("Enter character you wish, will be printed at current cursor address\n\r");
   		  *value=getchar();
   		  lcdputch(*value);
   		  free(value);
  	 	  break;
case '4': printf("Enter a String,control will print it at the current cursor location\n\r");
  			i=0;
 			
  				str=(xdata char *)malloc(300);
				gets(str);
				
  			
  			
   				lcdputstr(str);
  				
   				free(str);
  				break;
  				
case '5': lcdData(0x01,0);
	   	lcddelay(500);
	   	break;
case 'R': breaker=1;
  		  break;
	}	
   
  
   
}   
   
 
}
